package com.webmarmun;
import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;


public class Nekaznjavanje extends Activity implements OnClickListener{
	 private Button startNarucivanje;
	    private TextView mDateDisplay;
	private Button mPickDate;
	private int mYear;
	private int mMonth;
	private int mDay;
	private RadioButton rb1;
	private RadioButton rb2;
	private RadioButton rb3;
	private String array_spinner[];
	private String ime;
	private String prezime;
	private String imeoca;
	private String datumRodjenja;
	private String mesto;
	private String JMBG;
	private String opstina;
	private String email;
	private String razlog;
	private String lokacija;
	private String emailtext;
	private String subject="Poručivanje uverenja - android";
	private String address="bogicevicsasa@yahoo.com";
	static final int DATE_DIALOG_ID = 0;
	@Override
	 public void onCreate(Bundle savedInstanceState) {
		
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.nekaznjavanje);
	       
	        
	        startNarucivanje = (Button) findViewById(R.id.narucivanje);
	        startNarucivanje.setOnClickListener(this);
	        
	        // capture our View elements
	        mDateDisplay = (TextView) findViewById(R.id.dateDisplay);
	        mPickDate = (Button) findViewById(R.id.pickDate);
	        Button backButton =(Button)findViewById(R.id.back);
	        backButton.setOnClickListener(buttonhandler);
	        
	        
	        // add a click listener to the button
	        mPickDate.setOnClickListener(new View.OnClickListener() {
	            public void onClick(View v) {
	                showDialog(DATE_DIALOG_ID);
	            }
	        });
	        final Calendar c = Calendar.getInstance();
	        mYear = c.get(Calendar.YEAR);
	        mMonth = c.get(Calendar.MONTH);
	        mDay = c.get(Calendar.DAY_OF_MONTH);

	        // display the current date (this method is below)
	        updateDisplay();
	        rb1=(RadioButton)findViewById(R.id.option1);
	        rb2=(RadioButton)findViewById(R.id.option2);
	        rb3=(RadioButton)findViewById(R.id.option3);
	        array_spinner=new String[6];
	        array_spinner[0]="Услужни центар општине Нови Београд, Блок 70, Јурија Гагарина 81";
	        array_spinner[1]="Услужни центар општине Борча, Ивана Милутиновића 12г";
	        array_spinner[2]="Булевар Михајла Пупина 16";
	        array_spinner[3]="Тимочка 15";
	        array_spinner[4]="Устаничка 14";
	        array_spinner[5]="Палата правде Савска 17a";
	        Spinner s = (Spinner) findViewById(R.id.Spinner01);
	        ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item, array_spinner);
	        s.setAdapter(adapter);
	       
	    }

	    public void onClick(View v) {
	        if(rb1.isChecked() == true){
	                 RadioButton textradio1 = (RadioButton)findViewById(R.id.option1);
	                  razlog =textradio1.getText().toString();
	        }
	                
	        if(rb2.isChecked() == true){
	                RadioButton textradio2 = (RadioButton)findViewById(R.id.option1);
	                  razlog =textradio2.getText().toString();
	        }
	        if(rb3.isChecked() == true){
	          EditText textrazlog = (EditText)findViewById(R.id.ostalo);
	                  razlog =textrazlog.getText().toString();
	        }
	        EditText textime = (EditText)findViewById(R.id.ime);
	        ime=textime.getText().toString();
	        
	        EditText textprezime = (EditText)findViewById(R.id.prezime);
	        prezime=textprezime.getText().toString();
	        
	        EditText textimeoca = (EditText)findViewById(R.id.imeoca);
	        imeoca=textimeoca.getText().toString();
	        
	        TextView textdatum = (TextView)findViewById(R.id.dateDisplay);
	        datumRodjenja=textdatum.getText().toString();
	        
	        EditText textmesto = (EditText)findViewById(R.id.mesto);
	        mesto=textmesto.getText().toString();
	        
	        EditText textopstina = (EditText)findViewById(R.id.opstina);
	        opstina=textopstina.getText().toString();
	        
	        EditText textjmbg = (EditText)findViewById(R.id.jmbg);
	        JMBG=textjmbg.getText().toString();
	        
	        EditText textmail = (EditText)findViewById(R.id.email);
	        email=textmail.getText().toString();
	        
	        Spinner textlokacija = (Spinner)findViewById(R.id.Spinner01);
	        lokacija=textlokacija.getSelectedItem().toString();
	        emailtext= "Ime : "+this.ime+"\n"+
	                   "Prezime : "+prezime+"\n"+
	                   "Ime oca : "+imeoca+"\n"+
	                   "Datum rodjenja : "+datumRodjenja+"\n"+
	                   "Mesto rodjenja : "+mesto+"\n"+
	                   "Opstina : "+opstina+"\n"+
	                   "JMBG : "+JMBG+"\n"+
	                   "E mail : "+email+"\n"+
	                   "Uverenje mi je potrebno radi : "+razlog+"\n"+
	                   "Mesto preuzimanja : "+lokacija+"\n";
	        
	        final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
	        
	        emailIntent.setType("text/plain");

	        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{address});

	        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);

	        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext);

	        Nekaznjavanje.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
	                
	      }
	    // updates the date in the TextView
	    private void updateDisplay() {
	        mDateDisplay.setText(
	            new StringBuilder()
	                    // Month is 0 based so add 1
	                    .append(mMonth + 1).append("-")
	                    .append(mDay).append("-")
	                    .append(mYear).append(" "));
	    }


	    private DatePickerDialog.OnDateSetListener mDateSetListener =
	        new DatePickerDialog.OnDateSetListener() {
	                        @Override
	                        public void onDateSet(DatePicker view, int year, int monthOfYear,
	                                        int dayOfMonth) {
	                                mYear = year;
	                mMonth = monthOfYear;
	                mDay = dayOfMonth;
	                updateDisplay();
	                                
	                        }
	        };
	        
	        
	        protected Dialog onCreateDialog(int id) {
	            switch (id) {
	            case DATE_DIALOG_ID:
	                return new DatePickerDialog(this,
	                            mDateSetListener,
	                            mYear, mMonth, mDay);
	            }
	            return null;
	        }
	        
	        View.OnClickListener buttonhandler=new View.OnClickListener() { 

		 		 
	 		      public void onClick(View v) {
	 		          Intent myIntent1 = new Intent(Nekaznjavanje.this, AndredActivity.class);
	 		          Nekaznjavanje.this.startActivity(myIntent1);
	 		      
	 		    } 
	        };
}
